package bTree.LeetCode;

public class 字母移位 {
    public String shiftingLetters(String s, int[] shifts) {
        int length = s.length();
        int[] preSum = new int[length];
        preSum[length - 1] = shifts[length - 1];
        for (int i = length - 2; i >= 0; i--) {
            shifts[i]%=26;
            preSum[i] = preSum[i + 1] + shifts[i];
        }
        StringBuilder sb = new StringBuilder(s);
        for (int i = 0; i < sb.length(); i++) {
            int i1 = preSum[i];
            i1 %= 26;
            char c = sb.charAt(i);
            c += (char) i1;
            if (c>122){
                c= (char) (c%122+'a'-1);
            }
            sb.replace(i, i+1, String.valueOf(c));
        }
        return sb.toString();
    }

}